package com.dreamcar.auction.entity;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.OneToOne;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "request", catalog = "assignment")
public class Request implements java.io.Serializable {

	// Fields

	private Integer idRequest;
	private Component component;
	private DreamcarEmployee dreamcarEmployee;
	private Timestamp finishDate;
	private BigDecimal priceThreshold;
	private Integer quantity;
	private String status;
	private PurchaseOrder purchaseOrder;
	private Set<Bid> bids = new HashSet<Bid>(0);

	// Constructors

	/** default constructor */
	public Request() {
	}

	/** full constructor */
	public Request(Component component, DreamcarEmployee dreamcarEmployee,
			Timestamp finishDate, BigDecimal priceThreshold, Integer quantity,
			String status, PurchaseOrder purchaseOrder, Set<Bid> bids) {
		this.component = component;
		this.dreamcarEmployee = dreamcarEmployee;
		this.finishDate = finishDate;
		this.priceThreshold = priceThreshold;
		this.quantity = quantity;
		this.status = status;
		this.purchaseOrder = purchaseOrder;
		this.bids = bids;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id_request", unique = true, nullable = false)
	public Integer getIdRequest() {
		return this.idRequest;
	}

	public void setIdRequest(Integer idRequest) {
		this.idRequest = idRequest;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_component")
	public Component getComponent() {
		return this.component;
	}

	public void setComponent(Component component) {
		this.component = component;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_dreamcar_employee")
	public DreamcarEmployee getDreamcarEmployee() {
		return this.dreamcarEmployee;
	}

	public void setDreamcarEmployee(DreamcarEmployee dreamcarEmployee) {
		this.dreamcarEmployee = dreamcarEmployee;
	}

	@Column(name = "finish_date", length = 19)
	public Timestamp getFinishDate() {
		return this.finishDate;
	}

	public void setFinishDate(Timestamp finishDate) {
		this.finishDate = finishDate;
	}

	@Column(name = "price_threshold")
	public BigDecimal getPriceThreshold() {
		return this.priceThreshold;
	}

	public void setPriceThreshold(BigDecimal priceThreshold) {
		this.priceThreshold = priceThreshold;
	}

	@Column(name = "quantity")
	public Integer getQuantity() {
		return this.quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	@Column(name = "status", length = 10)
	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "request")
	public PurchaseOrder getPurchaseOrder() {
		return this.purchaseOrder;
	}

	public void setPurchaseOrder(PurchaseOrder purchaseOrder) {
		this.purchaseOrder = purchaseOrder;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "request")
	public Set<Bid> getBids() {
		return this.bids;
	}

	public void setBids(Set<Bid> bids) {
		this.bids = bids;
	}

}